package cn.afactory.tygz.ui.activities;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.AttributeSet;
import android.view.View;

import com.tendcloud.tenddata.TCAgent;

import cn.afactory.tygz.R;
import cn.afactory.tygz.model.LifeServiceInfo;
import cn.afactory.tygz.ui.base.BaseFragmentActivity;
import cn.afactory.tygz.ui.fragments.LifeServiceDetailFragment;
import cn.afactory.tygz.ui.sns.fragment.SubjectDetailFragment;

/**
 * Created by Kenneth on 15/9/17.
 */
public class LifeServiceDetailActivity extends BaseFragmentActivity {

    public final static String EXT_DATA_TAG = "lifeServiceInfo";
    private LifeServiceInfo lifeServiceInfo;
    private LifeServiceDetailFragment mFragment;

    private int mPageIndex = 0;

    public void setPageIndex(int index) {
        mPageIndex = index;
    }

    @Override
    public View onCreateView(String name, Context context, AttributeSet attrs) {
        return super.onCreateView(name, context, attrs);
    }

    @Override
    public void onResume() {
        super.onResume();
        TCAgent.onResume(this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addTitleBar = false;
        setContentView(R.layout.ac_fragment);
        lifeServiceInfo = (LifeServiceInfo)getIntent().getSerializableExtra(LifeServiceDetailActivity.EXT_DATA_TAG);
        initview();
    }

    private void initview() {
        mFragment = new LifeServiceDetailFragment();
        if (mFragment != null) {
            Bundle bundle = new Bundle();
            bundle.putSerializable(LifeServiceDetailActivity.EXT_DATA_TAG, lifeServiceInfo);
            mFragment.setArguments(bundle);
            addFragment(mFragment);
        } else {
            finish();
        }
    }

    private void addFragment(Fragment fragment) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.fl_layout, fragment, "" + fragment.getClass())
                .commit();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == SubjectDetailFragment.REQUEST_CODE_COMMENT) {
            mFragment.startLoadData(true);
        }
    }
}